<template>
	<view class="card mint" style="display: flex;justify-content: space-around;align-items: center;">
		<view style="display: flex;flex-direction: column;">
			<view>
				邀请您加入团队
			</view>
			<view style="display: flex;gap: 5px;align-items: center;padding: 5px 0;">
				<tn-avatar :url="sConf.pics + data.source.face" size="sm" shadow></tn-avatar>
				<view style="font-size: small;font-weight: bold;"> {{ data.source.nicename }}</view>
			</view>
			<view style="padding: 5px 0;font-size: large;font-weight: bolder;text-wrap: wrap;">
				{{ data.desc }}
			</view>
			<view style="font-size: smaller;">
				{{ data.created }}
			</view>
		</view>
		<view style="padding: 5px;">
			<view v-if="data.status === 0" style="display: flex;flex-direction: column;gap: 15px;">
				<view class="forest" @click="InviteChange(1)"
					style="font-size: smaller;display: flex;align-items: center;gap: 5px;padding: 5px 10px;border-radius: 5px;">
					<tn-icon name="success-circle" size="32"></tn-icon>
					<view class=""> 同意 </view>
				</view>
				<view class="berry" @click="InviteChange(2)"
					style="font-size: smaller;display: flex;align-items: center;gap: 5px;padding: 5px 10px;border-radius: 5px;">
					<tn-icon name="close-circle" size="32"></tn-icon>
					<view class=""> 拒绝 </view>
				</view>
			</view>
			<tn-icon v-if="data.status === 1" name="success-circle" size="64" color="#4cd964"></tn-icon>
			<tn-icon v-if="data.status === 2" name="close-circle" size="64" color="#dd524d"></tn-icon>
		</view>
	</view>
</template>

<script>
import utils from '@/common/utils';
export default {
	name: "sub-message-invite",
	data() {
		return {
			sConf: getApp().globalData,
			test: 'abcde',
		};
	},
	mounted() {
		console.log('mounted');
	},
	props: {
		data: {
			type: Object,
			default: null
		}
	},
	methods: {
		/**
		 * 确认事件
		 * @param {Object} e
		 */
		InviteChange(e) {
			let that = this;
			let scc = e === 1 ? '同意' : '拒绝';
			uni.showModal({
				title: scc,
				content: '是否要 ' + scc + ' 这份邀请？不能撤销的哦。',
				success(res) {
					if (res.confirm) {
						console.log('同意了');
						that.patchInviteState(e);
					}
				}
			})
		},
		/**
		 * 应答状态
		 * @param {Object} e
		 */
		patchInviteState(e) {
			let host = this.sConf.host + '/weapps/invite/' + this.data.id + '/';
			let token = this.sConf.token || ''
			let data = {
				status: e
			}
			utils.authenticatorOnPatch(host, token, data).then(res => {
				console.log('应答邀约状态', res);
				this.$emit('stateChange')
			}).catch(err => {
				console.log('应答邀约状态__失败', err);
				uni.showToast({
					icon: 'error',
					title: '应答失败'
				})
			})
		}
	}
}
</script>

<style lang="scss" scoped></style>